﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// PixelateEffect Effect
    /// </summary>
    public class PixelateEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(PixelateEffect), 0);
        public static readonly DependencyProperty HorizontalPixelCountsProperty = DependencyProperty.Register("HorizontalPixelCounts", typeof(double), typeof(PixelateEffect), new UIPropertyMetadata(80.0, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty VerticalPixelCountsProperty = DependencyProperty.Register("VerticalPixelCounts", typeof(double), typeof(PixelateEffect), new UIPropertyMetadata(80.0, ShaderEffect.PixelShaderConstantCallback(1)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(PixelateEffect.InputProperty));
            }
            set
            {
                this.SetValue(PixelateEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété HorizontalPixelCounts du Shader
        /// </summary>
        public double HorizontalPixelCounts
        {
            get
            {
                return ((double)this.GetValue(PixelateEffect.HorizontalPixelCountsProperty));
            }
            set
            {
                this.SetValue(PixelateEffect.HorizontalPixelCountsProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété VerticalPixelCounts du Shader
        /// </summary>
        public double VerticalPixelCounts
        {
            get
            {
                return ((double)this.GetValue(PixelateEffect.VerticalPixelCountsProperty));
            }
            set
            {
                this.SetValue(PixelateEffect.VerticalPixelCountsProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static PixelateEffect()
        {
            PixelateEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/Pixelate.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public PixelateEffect()
        {
            this.PixelShader = PixelateEffect._PixelShader;

            this.UpdateShaderValue(PixelateEffect.InputProperty);
            this.UpdateShaderValue(PixelateEffect.HorizontalPixelCountsProperty);
            this.UpdateShaderValue(PixelateEffect.VerticalPixelCountsProperty);
        }

        #endregion
    }
}
